home *** CD-ROM | disk | FTP | other *** search
/ Gurewich OLE Controls for Visual Basic 4 / Gurewich OLE Controls for Visual Basic 4.iso / ocxprog / programs / ch15 / wingbmp.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-08-25  |  6.1 KB  |  200 lines

  1. VERSION 4.00
  2. Begin VB.Form frmWinGBMP 
  3.    Caption         =   "The WinG BMP Program"
  4.    ClientHeight    =   5010
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1830
  7.    ClientWidth     =   6720
  8.    Height          =   5700
  9.    Icon            =   "WINGBMP.frx":0000
  10.    Left            =   1035
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   5010
  13.    ScaleWidth      =   6720
  14.    Top             =   1200
  15.    Width           =   6840
  16.    Begin MSComDlg.CommonDialog CommonDialog1 
  17.       Left            =   120
  18.       Top             =   120
  19.       _Version        =   65536
  20.       _ExtentX        =   847
  21.       _ExtentY        =   847
  22.       _StockProps     =   0
  23.       CancelError     =   -1  'True
  24.    End
  25.    Begin TegwingLibCtl.Tegwing Tegwing1 
  26.       Left            =   840
  27.       Top             =   120
  28.       _version        =   65536
  29.       _extentx        =   1032
  30.       _extenty        =   953
  31.       _stockprops     =   0
  32.    End
  33.    Begin VB.Menu mnuFile 
  34.       Caption         =   "&File"
  35.       Begin VB.Menu mnuOpen 
  36.          Caption         =   "&Open..."
  37.       End
  38.       Begin VB.Menu mnuSep1 
  39.          Caption         =   "-"
  40.       End
  41.       Begin VB.Menu mnuInfo 
  42.          Caption         =   "&Info..."
  43.       End
  44.       Begin VB.Menu mnuSep2 
  45.          Caption         =   "-"
  46.       End
  47.       Begin VB.Menu mnuExit 
  48.          Caption         =   "E&xit"
  49.       End
  50.    End
  51.    Begin VB.Menu mnuHelp 
  52.       Caption         =   "&Help"
  53.       Begin VB.Menu mnuAbout 
  54.          Caption         =   "&About..."
  55.       End
  56.    End
  57. Attribute VB_Name = "frmWinGBMP"
  58. Attribute VB_Creatable = False
  59. Attribute VB_Exposed = False
  60. Option Explicit
  61. ' Constants.
  62. Const SRCERASE = &H440328
  63. Const SRCINVERT = &H660046
  64. Const SRCPAINT = &HEE0086
  65. Const SRCAND = &H8800C6
  66. Const SRCCOPY = &HCC0020
  67. Dim gBMPHandle As Integer
  68. Private Sub Form_Load()
  69.     ' Open WinG.
  70.     Tegwing1.hWndDisplay = Me.hWnd
  71.     Tegwing1.OpenWinG
  72.     Me.ScaleMode = 3
  73. End Sub
  74. Private Sub Form_Paint()
  75.     ' Display the BMP file (if the BMP is open).
  76.     If gBMPHandle > 0 Then
  77.        DisplayBitmap (gBMPHandle)
  78.     End If
  79. End Sub
  80. Private Sub Form_Resize()
  81.     ' Close current WinG, start a new
  82.     ' WinG session, and display the bitmap.
  83.     Tegwing1.CloseWinG
  84.     Tegwing1.hWndDisplay = Me.hWnd
  85.     Tegwing1.OpenWinG
  86.     If gBMPHandle <> 0 Then
  87.        DisplayBitmap (gBMPHandle)
  88.     End If
  89. End Sub
  90. Private Sub Form_Unload(Cancel As Integer)
  91.     ' Close WinG and close the bitmap.
  92.     Tegwing1.CloseWinG
  93.     Tegwing1.CloseBMP gBMPHandle
  94. End Sub
  95. Private Sub mnuAbout_Click()
  96.    Dim Title
  97.    Dim Msg
  98.    Dim CR
  99.    CR = Chr(13) + Chr(10)
  100.    ' The title of the About message box.
  101.    Title = "About the WinG BMP Program"
  102.    ' Prepare the message of the About message box.
  103.    Msg = "This program was written with Visual "
  104.    Msg = Msg + "Basic for Windows, using the "
  105.    Msg = Msg + "TegoSoft WinG OCX control. "
  106.    Msg = Msg + CR + CR
  107.    Msg = Msg + "The TegoSoft WinG OCX control "
  108.    Msg = Msg + "enables you to perform fast graphics "
  109.    Msg = Msg + "operations (such as display BMP files) "
  110.    Msg = Msg + "using WinG technology."
  111.    Msg = Msg + CR + CR
  112.    Msg = Msg + "The TegoSoft WinG OCX control "
  113.    Msg = Msg + "is part of the TegoSoft OCX Control "
  114.    Msg = Msg + "Kit - a collection of various OCX controls. "
  115.    Msg = Msg + CR + CR
  116.    Msg = Msg + "For more information about the "
  117.    Msg = Msg + "TegoSoft OCX Control Kit, contact TegoSoft "
  118.    Msg = Msg + "at:"
  119.    Msg = Msg + CR + CR
  120.    Msg = Msg + "TegoSoft Inc." + CR
  121.    Msg = Msg + "P.O. Box 389" + CR
  122.    Msg = Msg + "Bellmore, NY 11710"
  123.    Msg = Msg + CR + CR
  124.    Msg = Msg + "Phone: (516)783-4824"
  125.    ' Display the About message box.
  126.    MsgBox Msg, vbInformation, Title
  127. End Sub
  128. Private Sub mnuExit_Click()
  129.     Unload Me
  130. End Sub
  131. Private Sub mnuInfo_Click()
  132.     Dim Msg
  133.     Dim BitmapWidth
  134.     Dim BitmapHeight
  135.     If gBMPHandle = 0 Then
  136.        Msg = "BMP is not open."
  137.     Else
  138.        BitmapWidth = Tegwing1.GetBMPWidth(gBMPHandle)
  139.        BitmapHeight = Tegwing1.GetBMPHeight(gBMPHandle)
  140.        Msg = "BMP Width:" + Str(BitmapWidth)
  141.        Msg = Msg + Chr(13) + Chr(10)
  142.        Msg = Msg + "BMP Height:" + Str(BitmapHeight)
  143.     End If
  144.     MsgBox Msg, vbInformation, "Info"
  145. End Sub
  146. Private Sub mnuOpen_Click()
  147. Dim Msg
  148. ' Display an Open File dialog box.
  149. On Error GoTo OpenFileError
  150. CommonDialog1.Filter = "All Files (*.*) | *.* |Bitmap Files (*.bmp)|*.bmp"
  151. CommonDialog1.FilterIndex = 2
  152. CommonDialog1.Action = 1
  153. On Error GoTo 0
  154. ' Close previous bitmap.
  155. Tegwing1.CloseBMP gBMPHandle
  156. ' Update the window's title.
  157. Me.Caption = "The WinG BMP Program"
  158. ' Clear the screen.
  159. ' Open the BMP.
  160. gBMPHandle = Tegwing1.OpenBMP(CommonDialog1.filename)
  161. ' If OpenBMP() failed, tell the user.
  162. If gBMPHandle = 0 Then
  163.    Msg = "Can't open " + CommonDialog1.filename
  164.    Msg = Msg + " (BMP must be 256 colors BMP file)."
  165.    MsgBox Msg, vbInformation, "Error"
  166.    Exit Sub
  167. End If
  168. ' Update window title and display the BMP.
  169. Me.Caption = "The WinG BMP Program - (" + CommonDialog1.FileTitle + ")"
  170. DisplayBitmap (gBMPHandle)
  171. Exit Sub
  172. OpenFileError:
  173. Exit Sub
  174. End Sub
  175. Public Sub DisplayBitmap(BMPHandle As Integer)
  176. Dim TypeOfStretch As Long
  177. Dim HandleOfSourceBMP As Integer
  178. Dim SourceWidth, SourceHeight As Integer
  179. Dim SourceX, SourceY As Integer
  180. Dim TargetWidth, TargetHeight As Integer
  181. Dim TargetX, TargetY As Integer
  182. ' Initialize variables.
  183. HandleOfSourceBMP = BMPHandle
  184. TypeOfStretch = SRCCOPY
  185. SourceWidth = Tegwing1.GetBMPWidth(BMPHandle)
  186. SourceHeight = Tegwing1.GetBMPHeight(BMPHandle)
  187. SourceY = 0
  188. SourceX = 0
  189. TargetY = 0
  190. TargetX = 0
  191. TargetWidth = Tegwing1.WinGWidth
  192. TargetHeight = Tegwing1.WinGHeight
  193. ' Copy the BMP file into WinG
  194. Tegwing1.CopyBMP2WinG TargetX, TargetY, TargetWidth, TargetHeight, _
  195.          HandleOfSourceBMP, SourceX, SourceY, _
  196.          SourceWidth, SourceHeight, TypeOfStretch
  197. ' Slam WinG into the screen.
  198.  Tegwing1.SlamIt
  199. End Sub
  200.